home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / rbbs_pc / newz20.zip / QUOTE.C < prev    next >
C/C++ Source or Header  |  1992-05-25  |  4KB  |  135 lines

  1. /****************************************************
  2.  
  3.  Compiled under TURBO C (2nd Ed). Small memory model.
  4.  Copyright (c) 1991 by James P. Storch
  5.  all right reserved
  6.  
  7.  Electric Harbor BBS (703) 730-0542
  8.  ****************************************************/
  9.  
  10. #include <dos.h>
  11. #include <stdio.h>
  12. #include <dir.h>
  13. #include <string.h>
  14. #define FALSE 0
  15. #define TRUE !FALSE
  16.  
  17. FILE *infile,*outfile;
  18.  
  19. struct date date;             /* date structure, from DOS.H                  */
  20. char line[150];
  21. int x, next;
  22.  
  23. char quote_path[100];          /* holds path for quote file to create */
  24. char last_quote[100];
  25.  
  26. int main(void){
  27.  
  28. /***************
  29.  Get todays date
  30.  ***************/
  31. getdate(&date);     /* date.da_day date.da_mon date.da_year */
  32.  
  33. /************************************
  34.  Open config file and get config info
  35.  ************************************/
  36. printf("\n\n\n--> Reading QUOTE.CFG\n");
  37. if ((infile=fopen("quote.cfg","rt"))==NULL){
  38.     printf("FAILURE TRYING TO OPEN QUOTE.CFG!\n");
  39.     exit(1);
  40.     }
  41.  
  42. /**************************************
  43.  Read the path for quote file to create
  44.  **************************************/
  45. fgets(line,81,infile);
  46. strncpy(quote_path,line,strlen(line)-1);
  47.  
  48. /*************************************
  49.  Get the number of the last quote used
  50.  *************************************/
  51. fscanf(infile,"%d",&next);
  52. printf("--> Next quote is %d.\n",next);
  53. fclose(infile);
  54.  
  55. /*******************************
  56.  Open the quote file for writing
  57.  and quote.dat for reading
  58.  *******************************/
  59. printf("--> Opening quote file %s.\n",quote_path);
  60. if((outfile=fopen(quote_path,"wt"))==NULL){
  61.     printf("FAILURE TRYING TO CREATE %s!\n",quote_path);
  62.     exit(1);
  63.     }
  64.  
  65. printf("--> Opening quote.dat and getting next quote.\n");
  66. if ((infile=fopen("QUOTE.DAT","rt"))==NULL){
  67.     printf("FAILURE TRYING TO OPEN QUOTE.DAT!\n");
  68.     exit(1);
  69.     }
  70.  
  71. /******************************************
  72.  Now, read past the last quote if quote.dat
  73.  if EOF, reset to start
  74.  ******************************************/
  75. while(x<next){
  76. if (fgets(line,81,infile)==NULL) {
  77.     printf("    EOF encountered, reseting to first quote.\n");
  78.     rewind(infile);
  79.     next=0;
  80.     break;
  81.         }
  82. if (strncmp(";",line,1)==0) x++;
  83. }
  84.  
  85. /********************************
  86.  Write to the quote file for NEWZ
  87.  ********************************/
  88. printf("--> This is todays quote:\n\n");
  89.  
  90. fprintf(outfile,"%d/%d/%d\n",date.da_mon,date.da_day,date.da_year);
  91. fprintf(outfile,"%d/%d/%d\n",date.da_mon,date.da_day,date.da_year);
  92. fprintf(outfile,"Quote of the Day\n");
  93.  
  94. for(;;){
  95. fgets(line,81,infile);
  96. if (!strncmp(";",line,1)) break;
  97. if (!strncmp("-EOF-",line,5)) break;
  98. fprintf(outfile,"%s",line);
  99. printf("%s",line);
  100. }
  101. printf("\n");
  102.  
  103. /******************************
  104.  close quote file and quote.dat
  105.  all done.
  106.  ******************************/
  107.  
  108. fclose(outfile);
  109. fclose(infile);
  110.  
  111. /*************************************************
  112.  Re-open config file and update next quote pointer
  113.  *************************************************/
  114. printf("--> Updating next quote pointer.\n");
  115. printf("    Writing to QUOTE.CFG\n");
  116. if ((outfile=fopen("quote.cfg","wt"))==NULL){
  117.     printf("FAILURE TRYING TO RE-OPEN QUOTE.CFG!\n");
  118.     exit(1);
  119.     }
  120.  
  121. fprintf(outfile,"%s\n",quote_path);
  122.  
  123. /*************************************
  124.  Get the number of the last quote used
  125.  *************************************/
  126. next++;
  127. fprintf(outfile,"%d\n",next);
  128. fclose(outfile);
  129.  
  130. printf("--> All done! Thank you for using QUOTE.");
  131. return(0);
  132. }
  133.  
  134.  
  135.